#include "stdafx.h"
#include "MainFrame.h"
#include "LabelExample.h"
#include "ButtonExample.h"
#include "CheckBoxExample.h"
#include "RadioButtonExample.h"
#include "TextBoxExample.h"
#include "SpinExample.h"
#include "ComboBoxExample.h"
#include "DatePickerExample.h"
#include "DivExample.h"
#include "LayoutDivExample.h"
#include "SplitLayoutDivExample.h"
#include "GridExample.h"
#include "TreeExample.h"
#include "ChartExample.h"
#include "DataCenter.h"
#include "TabViewExample.h"
#include "CalendarExample.h"
#include "LayoutButton.h"
#include "BlankExample.h"
#include "MenuExample.h"
#include "PaintExample.h"

MainFrame::MainFrame(){
    
}

MainFrame::~MainFrame(){
    
}

void MainFrame::loadFile(const String& fileName, FCView *view){
    FCUIXml::loadFile(fileName, view);
    FCLayoutDiv *layoutDiv = getLayoutDiv(L"divLayout");
    for (int i = 0; i < layoutDiv->m_views.size(); i++)
    {
        FCView *view = layoutDiv->m_views.get(i);
        if (view->getName().find(L"LayoutButton") == 0)
        {
            view->addEvent((FCTouchEventCallBack*)this, FCEventID_Click, this);
        }
    }
    String wPath = FCTran::stringToString(DataCenter::getAppPath()) + L"/";
    LabelExample *labelExample = new LabelExample();
    labelExample->setNative(getNative());
    labelExample->loadFile(wPath + L"labelexample.xml", getTabPage(L"TabPage"));
    ButtonExample *buttonExample = new ButtonExample();
    buttonExample->setNative(getNative());
    buttonExample->loadFile(wPath + L"buttonexample.xml", getTabPage(L"TabPage2"));
    CheckBoxExample *checkBoxExample = new CheckBoxExample();
    checkBoxExample->setNative(getNative());
    checkBoxExample->loadFile(wPath + L"checkboxexample.xml", getTabPage(L"TabPage3"));
    RadioButtonExample *radioButtonExample = new RadioButtonExample();
    radioButtonExample->setNative(getNative());
    radioButtonExample->loadFile(wPath + L"radiobuttonexample.xml", getTabPage(L"TabPage4"));
    TextBoxExample *textBoxExample = new TextBoxExample();
    textBoxExample->setNative(getNative());
    textBoxExample->loadFile(wPath + L"textboxexample.xml", getTabPage(L"TabPage5"));
    SpinExample *spinExample = new SpinExample();
    spinExample->setNative(getNative());
    spinExample->loadFile(wPath + L"spinexample.xml", getTabPage(L"TabPage6"));
    ComboBoxExample *comboBoxExample = new ComboBoxExample();
    comboBoxExample->setNative(getNative());
    comboBoxExample->loadFile(wPath + L"comboboxexample.xml", getTabPage(L"TabPage7"));
    DatePickerExample *dateTimePicker = new DatePickerExample();
    dateTimePicker->setNative(getNative());
    dateTimePicker->loadFile(wPath + L"datepickerexample.xml", getTabPage(L"TabPage8"));
    DivExample *divExample = new DivExample();
    divExample->setNative(getNative());
    divExample->loadFile(wPath + L"divexample.xml", getTabPage(L"TabPage9"));
    LayoutDivExample *layoutDivExample = new LayoutDivExample();
    layoutDivExample->setNative(getNative());
    layoutDivExample->loadFile(wPath + L"layoutdivexample.xml", getTabPage(L"TabPage10"));
    SplitLayoutDivExample *splitLayoutDivExample = new SplitLayoutDivExample();
    splitLayoutDivExample->setNative(getNative());
    splitLayoutDivExample->loadFile(wPath + L"splitlayoutdivexample.xml", getTabPage(L"TabPage11"));
    GridExample *gridExample = new GridExample();
    gridExample->setNative(getNative());
    gridExample->loadFile(wPath + L"gridexample.xml", getTabPage(L"TabPage12"));
    TreeExample *treeExample = new TreeExample();
    treeExample->setNative(getNative());
    treeExample->loadFile(wPath + L"treeexample.xml", getTabPage(L"TabPage13"));
    ChartExample *chartExample = new ChartExample();
    chartExample->setNative(getNative());
    chartExample->loadFile(wPath + L"chartexample.xml", getTabPage(L"TabPage15"));
    TabViewExample *tabViewExample = new TabViewExample();
    tabViewExample->setNative(getNative());
    tabViewExample->loadFile(wPath + L"tabviewexample.xml", getTabPage(L"TabPage16"));
    CalendarExample *calendarExample = new CalendarExample();
    calendarExample->setNative(getNative());
    calendarExample->loadFile(wPath + L"calendarexample.xml", getTabPage(L"TabPage17"));
    BlankExample *blankExample = new BlankExample();
    blankExample->setNative(getNative());
    blankExample->loadFile(wPath + L"blankexample.xml", getTabPage(L"TabPage18"));
    MenuExample *menuExample = new MenuExample();
    menuExample->setNative(getNative());
    menuExample->loadFile(wPath + L"menuexample.xml", getTabPage(L"TabPage19"));
    PaintExample *paintExample = new PaintExample();
    paintExample->setNative(getNative());
    paintExample->loadFile(wPath + L"paintexample.xml", getTabPage(L"TabPage20"));
    getNative()->update();
}

void MainFrame::callTouchEvent(String eventName, Object sender, FCTouchInfo touchInfo, Object invoke){
    FCView *view = (FCView*)sender;
    if (view->getName().find(L"LayoutButton") == 0)
    {
        FCTabView *tabView = getTabView(L"tabContent");
        tabView->setSelectedIndex(FCTran::strToInt(FCTran::replace(view->getName(), L"LayoutButton", L"")) - 1);
        tabView->update();
        tabView->invalidate();
    }
}

FCView* MainFrame::createView(xmlNodePtr node, const String& type){
    if (type == L"layoutbutton")
    {
        return new LayoutButton();
    }
    return FCUIXml::createView(node, type);
}
